package com.schoolcloud.front.controller;

import com.schoolcloud.common.model.PageDTO;
import com.schoolcloud.common.model.R;
import com.schoolcloud.front.entity.FroSchool;
import com.schoolcloud.front.query.FroSchoolQuery;
import com.schoolcloud.front.service.FroSchoolService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/front/school")
@RestController
@RequiredArgsConstructor
public class FroSchoolController {
    private final FroSchoolService schoolService;

    @GetMapping("/page")
    public R<PageDTO<FroSchool>> getFroSchoolPage(FroSchoolQuery query) {
        PageDTO<FroSchool> page = schoolService.getFroSchoolPage(query);
        return R.ok(page);
    }

    @PostMapping
    public R<FroSchool> createFroSchool(@RequestBody FroSchool froSchool) {
        FroSchool createdSchool = schoolService.createFroSchool(froSchool);
        return R.ok(createdSchool);
    }

    @PutMapping
    public R<FroSchool> updateFroSchool(@RequestBody FroSchool froSchool) {
        FroSchool updatedSchool = schoolService.updateFroSchool(froSchool);
        return R.ok(updatedSchool);
    }

    @DeleteMapping("/{id}")
    public R<Void> deleteFroSchool(@PathVariable String id) {
        schoolService.removeById(id);
        return R.ok();
    }

}
